package com.inossem.warehousestorage_inossem.adapter.outStorage;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.inossem.warehousestorage_inossem.R;
import com.inossem.warehousestorage_inossem.bean.outStorage.SNItemInfo;

import java.util.List;

/**
 * Created by leij on 2017/6/6.
 */

public class PackageDetailSNListAdapter extends BaseAdapter {

    private Context mContext;

    private LayoutInflater inflater;

    private List<SNItemInfo> mSNList;

    public PackageDetailSNListAdapter(Context context, List<SNItemInfo> snList) {
        mContext = context;
        mSNList = snList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mSNList.size();
    }

    @Override
    public Object getItem(int position) {
        return mSNList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        SNItemInfo snItem = mSNList.get(position);
        ViewHolder viewHolder;
        if (convertView == null || (convertView != null && convertView.getTag() == null)) {
            convertView = inflater.inflate(R.layout.view_out_storage_detail_sn, null);
            viewHolder = new ViewHolder();
            //初始化控件
            initView(viewHolder, convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        //初始化数据
        initData(mContext, viewHolder, convertView, snItem);
        return convertView;
    }

    private void initView(ViewHolder viewHolder, View view) {
        viewHolder.type = (TextView) view.findViewById(R.id.type);
        viewHolder.code = (TextView) view.findViewById(R.id.code);
        viewHolder.icon = (ImageView) view.findViewById(R.id.icon);
    }

    private void initData(Context context, ViewHolder viewHolder, View view, SNItemInfo snItemInfo) {
        viewHolder.code.setText(snItemInfo.getCode());
        viewHolder.type.setText("序列号");
        viewHolder.icon.setImageResource(R.drawable.test);
    }

    private class ViewHolder {
        private TextView type, code;

        private ImageView icon;

    }

}
